import 'package:flutter/material.dart';
import 'package:flutter_demo/dialog/alert_dialog.dart';
import 'package:get/get.dart';

import 'getx_route.dart';

class GetxPage extends StatelessWidget {
  const GetxPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("flutter Getx"),
          backgroundColor: Colors.blue,
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () {
                  alertDialog(context);
                },
                child: const Text('flutter默认的dialog'),
              ),
              ElevatedButton(
                onPressed: () {
                  Get.defaultDialog(
                    barrierDismissible: false,
                    title: '提示信息！',
                    middleText: '您确定要删除吗？',
                    confirm: ElevatedButton(
                      onPressed: () {
                        print('ok');
                        Get.back();
                      },
                      child: const Text('确定'),
                    ),
                    cancel: ElevatedButton(
                      onPressed: () {
                        print('cancel');
                        Get.back();
                      },
                      child: const Text('取消'),
                    ),
                  );
                },
                child: const Text('Getx defaultDialog'),
              ),
              ElevatedButton(
                onPressed: () {
                  Get.snackbar(
                    '提示信息！',
                    '您还没有登录',
                    icon: const Icon(Icons.accessibility_new),
                  );
                },
                child: const Text('Getx snackbar'),
              ),
              ElevatedButton(
                onPressed: () {
                  Color bgColor =
                      Get.isDarkMode ? Colors.black26 : Colors.white;
                  Color color = Get.isDarkMode ? Colors.white : Colors.black87;

                  Get.bottomSheet(
                    Container(
                      height: 200,
                      color: bgColor,
                      child: Column(
                        children: [
                          ListTile(
                            leading:
                                Icon(Icons.wb_sunny_outlined, color: color),
                            title: Text('白天模式', style: TextStyle(color: color)),
                            onTap: () {
                              Get.changeTheme(ThemeData.light());
                              Get.back();
                            },
                          ),
                          ListTile(
                            leading: Icon(Icons.wb_sunny, color: color),
                            title: Text('夜间模式', style: TextStyle(color: color)),
                            onTap: () {
                              Get.changeTheme(ThemeData.dark());
                              Get.back();
                            },
                          ),
                        ],
                      ),
                    ),
                  );
                },
                child: const Text('Getx bottomSheet切换主题'),
              ),
              ElevatedButton(
                onPressed: () {
                  Get.toNamed('/search', arguments: {'uid': 1234});
                },
                child: const Text('getx 路由跳转'),
              )
            ],
          ),
        ),
      ),
      defaultTransition: AppPages.defaultTransition,
      getPages: AppPages.routes,
    );
  }
}
